package com.dwxt.sport.business.controller;

import com.dwxt.common.base.BaseResult;
import com.dwxt.sport.business.entity.QuinquagenarianSportsHealth;
import com.dwxt.sport.business.entity.QuinquagenarianSportsHealthEquipment;
import com.dwxt.sport.business.service.QuinquagenarianService;
import com.dwxt.sport.business.vo.quinquagenarian.InsertOrUpdateQuinquagenarianVo;
import com.dwxt.sport.business.vo.quinquagenarian.InsertOrUpdateSportsHealthEquipmentVo;
import com.dwxt.sport.business.vo.quinquagenarian.SelectQuinquagenarianVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 中老年运动健康 Controller
 *
 * @author Kuang.JiaZhuo
 * @date 2020-07-30 14:31
 */
@RestController
@RequestMapping("/quinquagenarianSportsHealth")
@Api(tags={"中老年运动健康相关接口"})
public class QuinquagenarianController {

    @Resource
    QuinquagenarianService quinquagenarianService;

    @ApiOperation(value = "新增或修改中老年运动健康", notes = "新增或修改中老年运动健康", response = Integer.class)
    @PostMapping("/back/insertOrUpdateQuinquagenarianSportsHealth")
    public BaseResult insertOrUpdateQuinquagenarianSportsHealth(InsertOrUpdateQuinquagenarianVo insertOrUpdateVo){
        int result = this.quinquagenarianService.insertOrUpdateQuinquagenarianSportsHealth(insertOrUpdateVo);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "获取中老年运动健康列表", notes = "按条件查询中老年运动健康列表(带分页)", response = QuinquagenarianSportsHealth.class)
    @PostMapping("/back/selectQuinquagenarianSportsHealthByCriteria")
    public BaseResult selectQuinquagenarianSportsHealthByCriteria(SelectQuinquagenarianVo selectVo){
        PageInfo<QuinquagenarianSportsHealth> pageInfo = this.quinquagenarianService.selectQuinquagenarianSportsHealthByCriteria(selectVo);
        return BaseResult.ok(pageInfo);
    }

    @ApiOperation(value = "删除中老年运动健康", notes = "根据ids批量删除中老年运动健康", response= Integer.class)
    @PostMapping(value = "/back/deleteQuinquagenarianSportsHealthByIds")
    public BaseResult deleteQuinquagenarianSportsHealthByIds(@ApiParam(value = "要删除的id字符串,以英文逗号隔开", required = true) @RequestParam String ids){
        int result = this.quinquagenarianService.deleteQuinquagenarianSportsHealthByIds(ids);
        return BaseResult.ok(result);
    }


    /******************************************************************  关联设备  ******************************************************************************/

    @ApiOperation(value = "新增 或 更新中老年运动健康设备关联", notes = "新增 或 更新中老年运动健康设备关联", response = Integer.class)
    @PostMapping("/back/insertOrUpdateRelationEquipment")
    public BaseResult insertOrUpdateRelationEquipment(InsertOrUpdateSportsHealthEquipmentVo insertOrUpdateVo){
        int result = this.quinquagenarianService.insertOrUpdateRelationEquipment(insertOrUpdateVo);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "删除【中老年运动健康】设备关联", notes = "根据ids批量删除【中老年运动健康】设备关联", response= Integer.class)
    @PostMapping(value = "/back/deleteRelationEquipmentByIds")
    public BaseResult deleteRelationEquipmentByIds(@ApiParam(value = "要删除的id字符串,以英文逗号隔开", required = true) @RequestParam String ids){
        int result = this.quinquagenarianService.deleteRelationEquipmentByIds(ids);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "查询【中老年运动健康】的设备列表", notes = "根据【中老年运动健康】的id查询关联设备的列表(带分页)", response= QuinquagenarianSportsHealthEquipment.class)
    @PostMapping(value = "/back/selectRelationEquipmentByCriteria")
    public BaseResult selectRelationEquipmentByCriteria(@ApiParam(value = "中老年运动健康关联id", required = true) @RequestParam String id,
                                                                      @ApiParam(value = "起始页", required = true) @RequestParam Integer pageNum,
                                                                      @ApiParam(value = "页大小", required = true) @RequestParam Integer pageSize){
        String healthId = id;
        PageInfo<QuinquagenarianSportsHealthEquipment> pageInfo = this.quinquagenarianService.selectRelationEquipmentByCriteria(pageNum,pageSize,healthId);
        return BaseResult.ok(pageInfo);
    }
}
